﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BGCOP.CAVTOP.BUSINESSLAYER;

namespace BGCOP.CAVTOP.WINFORMS
{
    public partial class frmEmpleadoOk : Form
    {
        public frmEmpleadoOk()
        {
            InitializeComponent();
        }

        private void tEmpleadoBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Desea realizar las operaciones pendientes?", Properties.Settings.Default.Titulo,
                MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                this.Validate();
                this.tEmpleadoBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.masterDBACDataSet);
                //falta cambiar estado tarjeta

                //llenaT();
                MessageBox.Show("El registro se proceso con exito!", Properties.Settings.Default.Titulo
                                , MessageBoxButtons.OK);
            }
            
            
        }

        private void frmEmpleadoOk_Load(object sender, EventArgs e)
        {

            centrarPanel();
            tInicio.Enabled = true;

        }

        private void idTipoIdentificacionTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                cmbTipoIdentificacion.SelectedValue = Convert.ToInt32( idTipoIdentificacionTextBox.Text) ;
            }
            catch (Exception)
            {

                cmbTipoIdentificacion.SelectedIndex = -1;
            }
        }

        private void cmbTipoIdentificacion_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbTipoIdentificacion.SelectedIndex >= 0)
            {
                idTipoIdentificacionTextBox.Text = cmbTipoIdentificacion.SelectedValue.ToString();
            }
        }

        private void notarjetaTextBox_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void cmbTarjetas_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbTarjetas.SelectedIndex >= 0)
            {
                idTarjetaTextBox.Text = cmbTarjetas.SelectedValue.ToString();
            }
        }

        private void idEmpresaTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                cmbEmpresa.SelectedValue = Convert.ToInt32(idEmpresaTextBox.Text);
                
            }
            catch (Exception)
            {

                cmbEmpresa.SelectedIndex = -1;
            }
            try
            {
                DivisionesEmpresa de = new DivisionesEmpresa();
                cmbDivision.DataSource = de.ListarTodas(Convert.ToInt32(idEmpresaTextBox.Text));
                cmbDivision.DisplayMember = "NombreDivision";
                cmbDivision.ValueMember = "IdDivisionEmpresa";
            }
            catch (Exception)
            {
                
                
            }
        }

        private void cmbEmpresa_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbEmpresa.SelectedIndex >= 0)
            {
                idEmpresaTextBox.Text = cmbEmpresa.SelectedValue.ToString();
            }
        }

        private void cmbDivision_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDivision.SelectedIndex >= 0)
            {
                idDivisionEmpresaTextBox.Text = cmbDivision.SelectedValue.ToString();
            }
        }

        private void idCargoTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                cmbCargos.SelectedValue = Convert.ToInt32(idCargoTextBox.Text);
            }
            catch (Exception)
            {

                cmbCargos.SelectedIndex = -1;
            }
        }

        private void cmbCargos_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbCargos.SelectedIndex >= 0)
            {
                idCargoTextBox.Text = cmbCargos.SelectedValue.ToString();
            }
        }

        private void idTarjetaTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string valor = idTarjetaTextBox.Text;
                cmbTarjetas.SelectedValue =  Convert.ToInt32(idTarjetaTextBox.Text);
                
            }
            catch (Exception)
            {

                cmbTarjetas.SelectedIndex = -1;
            }
        }

        private void frmEmpleadoOk_SizeChanged(object sender, EventArgs e)
        {
            centrarPanel();
        }
        public void centrarPanel()
        {
            //centrar el panel
            panel3.Top = ((this.Height - panel3.Height) / 2) + (panel2.Height / 2);
            panel3.Left = (this.Width - panel3.Width)/2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int pos = -1;
            if (radioButton1.Checked == true)
            {
                pos = tEmpleadoBindingSource.Find("identificacion", textBox1.Text);
            }
            else
            {
                pos = tEmpleadoBindingSource.Find("nombre", textBox1.Text);
            }
            if (pos == -1)
            {
                radDesktopAlert1.ContentImage = BGCOP.CAVTOP.WINFORMS.Properties.Resources.cancel_icon;
                radDesktopAlert1.CaptionText = "Busqueda...";
                radDesktopAlert1.ContentText = "No se ha encontrado ningun registro!";
                radDesktopAlert1.FixedSize = new Size(450, 140);
                radDesktopAlert1.Show();
                return;
            }
            else
            {
                textBox1.Text = "";
            }
            tEmpleadoBindingSource.Position = pos;

        }

        private void cmbEstado_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbEstado.SelectedIndex >= 0)
            {
                idTipoEstadoTextBox.Text = cmbEstado.SelectedValue.ToString();
            }
        }

        private void idTipoEstadoTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                cmbEstado.SelectedValue = Convert.ToInt32(idTipoEstadoTextBox.Text);
            }
            catch (Exception)
            {

                cmbEstado.SelectedIndex = -1;
            }
        }
        public void llenaT()
        {
            Tarjetas tj = new Tarjetas();
            cmbTarjetas.DataSource = tj.ListarTodas();
            cmbTarjetas.DisplayMember = "numtarjeta";
            cmbTarjetas.ValueMember = "idTarjeta";
        }
        private void tInicio_Tick(object sender, EventArgs e)
        {
            tInicio.Enabled = false;
            // TODO: This line of code loads data into the 'masterDBACDataSet.TEmpresa' table. You can move, or remove it, as needed.
            this.tEmpresaTableAdapter.Fill(this.masterDBACDataSet.TEmpresa);
            TiposIdentificacion ti = new TiposIdentificacion();
            cmbTipoIdentificacion.DataSource = ti.ListarTodos();
            cmbTipoIdentificacion.DisplayMember = "descripcionIdentificacion";
            cmbTipoIdentificacion.ValueMember = "idTipoIdentificacion";

            llenaT();

            Empresas em = new Empresas();
            cmbEmpresa.DataSource = em.ListarTodas();
            cmbEmpresa.DisplayMember = "RazonSocial";
            cmbEmpresa.ValueMember = "idEmpresa";

            Cargos cg = new Cargos();
            cmbCargos.DataSource = cg.ListarTodas();
            cmbCargos.DisplayMember = "NombreCargo";
            cmbCargos.ValueMember = "idCargo";

            EstadosEmpleado est = new EstadosEmpleado();
            cmbEstado.DataSource = est.ListarTodos();
            cmbEstado.DisplayMember = "NombreEstado";
            cmbEstado.ValueMember = "idTipoEstado";

            // TODO: This line of code loads data into the 'masterDBACDataSet.TEmpleado' table. You can move, or remove it, as needed.
            this.tEmpleadoTableAdapter.Fill(this.masterDBACDataSet.TEmpleado);
        }

        
    }
}
